package com.tfswx.jcyw.ruleenginedesigner.api;

import com.tfswx.jcyw.ruleenginedesigner.bean.ApiResult;
import com.tfswx.jcyw.ruleenginedesigner.bean.SjysjItem;
import com.tfswx.jcyw.ruleenginedesigner.dto.sjygl.*;
import com.tfswx.jcyw.ruleenginedesigner.service.SjyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Ricky
 * @date 2021/5/13
 */
@RestController
@RequestMapping("/sjygl")
@Api(tags = "数据源管理")
public class SjyglController {
    @Resource
    private SjyService sjyService;

    @ApiOperation("获取数据源")
    @PostMapping("/querySjyList")
    public ApiResult<List<SjyListQueryOutputDTO>> querySjyList(@NonNull @RequestBody @Validated SjyListQueryInputDTO sjyListQueryInputDTO) {
        List<SjyListQueryOutputDTO> sjyList = sjyService.querySjyList(sjyListQueryInputDTO);
        return ApiResult.success(sjyList);
    }

    @ApiOperation("获取数据源-配置实体使用")
    @PostMapping("/queryCanUseSjy")
    public ApiResult<List<CanUseSjyQueryOutputDTO>> queryCanUseSjy(@NonNull @RequestBody @Validated CanUseSjyQueryInputDTO canUseSjyQueryInputDTO) {
        List<CanUseSjyQueryOutputDTO> sjyList = sjyService.queryCanUseSjy(canUseSjyQueryInputDTO);
        return ApiResult.success(sjyList);
    }

    @ApiOperation("添加数据源")
    @PostMapping("/addSjy")
    public ApiResult<String> addSjy(@NonNull @RequestBody @Validated SjyAddInputDTO sjyAddInputDTO) {
        String sjybm = sjyService.addSjy(sjyAddInputDTO);
        return ApiResult.success(sjybm);
    }

    @ApiOperation("修改数据源")
    @PostMapping("/updateSjy")
    public ApiResult<Boolean> updateSjy(@NonNull @RequestBody @Validated SjyUpdateInputDTO sjyUpdateInputDTO) {
        boolean isSucc = sjyService.updateSjy(sjyUpdateInputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("删除数据源")
    @PostMapping("/deleteSjy")
    public ApiResult<Boolean> deleteSjy(@NonNull @RequestBody @Validated SjyDeleteInputDTO sjyDeleteInputDTO) {
        boolean isSucc = sjyService.deleteSjy(sjyDeleteInputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("恢复数据源")
    @PostMapping("/undeleteSjy")
    public ApiResult<Boolean> undeleteSjy(@NonNull @RequestBody @Validated SjyUndeleteInputDTO sjyUndeleteInputDTO) {
        boolean isSucc = sjyService.undeleteSjy(sjyUndeleteInputDTO);
        return ApiResult.success(isSucc);
    }

    @ApiOperation("获取数据源数据")
    @PostMapping("/getSjysj")
    public ApiResult<List<SjysjItem>> getSjysj(@NonNull @RequestBody @Validated SjysjGetInputDTO sjysjGetInputDTO) {
        List<SjysjItem> sjysj = sjyService.getSjysj(sjysjGetInputDTO);
        return ApiResult.success(sjysj);
    }
}
